﻿Imports System.Data.SqlClient

Public Class Form1
    Dim SqlConnection1 = New SqlConnection()
    Private Sub btnConnetti_Click(
          ByVal sender As System.Object,
          ByVal e As System.EventArgs) _
          Handles btnConnetti.Click
        If SqlConnection1.State = ConnectionState.Closed Then
            SqlConnection1.ConnectionString =
              "Integrated Security=SSPI;" &
              "Persist Security Info=False;" &
              "User ID='sa';" &
              "Initial Catalog=NorthWind;" &
              "Data Source=HP;" &
              "Initial File Name=''"
            SqlConnection1.Open()
        End If
        Me.Label1.Text = "Connesso"
    End Sub

    Private Sub btnDisconnetti_Click(
          ByVal sender As System.Object,
          ByVal e As System.EventArgs) _
          Handles btnDisconnetti.Click
        If SqlConnection1.State = ConnectionState.Open Then
            SqlConnection1.Close()
        End If
        Me.Label1.Text = "Disconnesso"
    End Sub

End Class
